package cn.frontop.funswitch.config.web;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Yun
 */
@Data
@Slf4j
public class ServiceContext {
    /**
     * 请求ID
     */
    public static final String REQUEST_ID = "requestId";
    /**
     * 私有
     */
    protected static final ThreadLocal<ServiceContext> LOCAL = ThreadLocal.withInitial(ServiceContext::new);

    private Map<String, Object> attributeMap = new ConcurrentHashMap<>(2);


    public static String getRequestId() {
        return (String) LOCAL.get().attributeMap.get(REQUEST_ID);
    }

    public static void setRequestId(String requestId) {
        LOCAL.get().attributeMap.put(REQUEST_ID, requestId);
    }

    public static void clearAll() {
        LOCAL.get().attributeMap.clear();
    }
}
